package cn.yuxirey.verifyedittext.app;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import cn.yuxirey.verifyedittext.OnCompleteListener;
import cn.yuxirey.verifyedittext.VerifyEditText;

/**
 * @author Administrator
 * @date 2022/3/14 17:38
 */
public class CodeDialog extends Dialog {

    public CodeDialog(@NonNull Context context) {
        super(context);
    }

    public CodeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected CodeDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_code);
        VerifyEditText editText = findViewById(R.id.verifyedittext);
        editText.setOnCompleteListener(new OnCompleteListener() {
            @Override
            public void onComplete(String code) {
                showToast("Code：" + code);
            }
        });

        Button btnOk = findViewById(R.id.btn_ok);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("OK: " + editText.getCodeString());
                dismiss();
            }
        });
    }

    private void showToast(String text) {
        Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
    }
}
